package com.xr.hr.care;

import com.xr.common.CommUtil;
import com.bstek.dorado.common.*;
import com.bstek.dorado.data.*;
import com.bstek.dorado.data.db.DBStatement;
import com.bstek.dorado.utils.variant.VariantSet;
import com.bstek.dorado.view.*;
import com.bstek.dorado.view.data.*;
import com.bstek.dorado.view.control.*;

/**
 * batchCreateViewModel
 */
public class batchCreateViewModel extends DefaultViewModel {
  protected void doUpdateData(ParameterSet parameters, ParameterSet outParameters)
      throws Exception {
    // Add your code here
    super.doUpdateData(parameters, outParameters);
  }
  public void create(ParameterSet parameters, ParameterSet outParameters)
			throws Exception {
	  DBStatement dbs = new DBStatement();
	  Dataset dsC = getDataset("datasetCreate");
	  String hritemsId=dsC.getString("hritems_id");
	  String sql="";
	  sql+="select * from org_onoff_station where 1=1 ";
	  if(dsC.getString("ONOFF_STATION_ID")!=null&& !dsC.getString("ONOFF_STATION_ID").equals("")){
		  sql+=" and ONOFF_STATION_ID="+dsC.getString("ONOFF_STATION_ID");
	  }
	  if(dsC.getString("DEPT_ID")!=null&& !dsC.getString("DEPT_ID").equals("")){
		  sql+=" and DEPT_ID="+dsC.getString("DEPT_ID");
	  }
	  if(dsC.getString("COMPANY_ID")!=null&& !dsC.getString("COMPANY_ID").equals("")){
		  sql+=" and COMPANY_ID="+dsC.getString("COMPANY_ID");
	  }
	  dbs.setSql(sql);
	  java.util.List list=dbs.queryForList();
	  for (int i=0;i<list.size();i++){
		  VariantSet vs=(VariantSet)list.get(i);
		  dbs.setSql("begin  pck_care.get"+hritemsId+"("+vs.getString("ONOFF_STATION_ID") + ","+dsC.getString("END_MONTH")+","+CommUtil.getEmployeeId()+"); end;");
		  dbs.execute();
		  dsC.moveNext();
	  }
	 
	dbs.close();

  }
  public void changeCareCreate(ParameterSet parameters, ParameterSet outParameters)throws Exception {
	  DBStatement dbs = new DBStatement();
	  Dataset dsC = getDataset("datasetCreate"); 
	  String sql=""; 
	  dbs.setSql("select * from pb_hritems h,pb_hritems_type pt where h.hritems_id=pt.hritems_id and pt.type_id=201");
	  java.util.List listItems=dbs.queryForList();
	  sql+="select * from org_onoff_station where 1=1 ";
	  if(dsC.getString("ONOFF_STATION_ID")!=null&& !dsC.getString("ONOFF_STATION_ID").equals("")){
		  sql+=" and ONOFF_STATION_ID="+dsC.getString("ONOFF_STATION_ID");
	  }
	  if(dsC.getString("DEPT_ID")!=null&& !dsC.getString("DEPT_ID").equals("")){
		  sql+=" and DEPT_ID="+dsC.getString("DEPT_ID");
	  }
	  if(dsC.getString("COMPANY_ID")!=null&& !dsC.getString("COMPANY_ID").equals("")){
		  sql+=" and COMPANY_ID="+dsC.getString("COMPANY_ID");
	  }
	  dbs.setSql(sql);
	  java.util.List list=dbs.queryForList();
	  for (int i=0;i<list.size();i++){
		  VariantSet vs=(VariantSet)list.get(i);
		  for(int j=0;j<listItems.size();j++){
			  VariantSet vsj=(VariantSet)listItems.get(j);
			  dbs.setSql("begin  pck_care.get"+vsj.getString("hritems_id")+"("+vs.getString("ONOFF_STATION_ID") + ","+dsC.getString("END_MONTH")+","+CommUtil.getEmployeeId()+"); end;");
			  dbs.execute();
		  }
		
		  dsC.moveNext();
	  }
	 
	dbs.close(); 
  }
  
  
  public void submit(ParameterSet parameters, ParameterSet outParameters)
	throws Exception {
	  DBStatement dbs = new DBStatement();
	  Dataset dsCare = getDataset("datasetEc");
	  
    	CommUtil.dbsUpdateData(dbs, dsCare, "emp_care","emp_care_id","seq_emp_care");
    	
    /*	RecordIterator ri = dsCare.recordIterator();
		ri.setVisibility(Dataset.FILTER_DELETED);
		while (ri.hasNext()) {
		  Record record = ri.nextRecord();
		  CommUtil.executeUpdate(dbs, "update emp_care set dr=1,dr_date=sysdate where emp_care_id="+record.getString("emp_care_id"));
		}*/
		dbs.close();
		
  }
  public void careDr(ParameterSet parameters, ParameterSet outParameters)
	throws Exception {
	  DBStatement dbs = new DBStatement();
	  Dataset dsCare = getDataset("datasetEc");
    dsCare.moveFirst();
	 
		while (!dsCare.isLast()) {
		 
		  CommUtil.executeUpdate(dbs, "update emp_care set dr=1,dr_date=sysdate where emp_care_id="+dsCare.getString("emp_care_id"));
		}
		dbs.close();
}
}
